package com.xdxc.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xdxc.mapper.ExamRecordMapper;
import com.xdxc.model.dto.ExamRecordDTO;
import com.xdxc.response.Result;
import com.xdxc.service.ExamRecordService;
import com.xdxc.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/examResult")
public class ExamResultController {

    @Autowired
    private ExamRecordService examRecordService;


    @Autowired
    private ExamRecordMapper examRecordMapper;

    @GetMapping("/user-paper-detail")
    public Result getPaperResult(@RequestParam Long paperId){

        return examRecordService.getPaperDetail(paperId);
    }


    @GetMapping("/pageExamRecord")
    public Result pageExamRecord(
            @RequestParam(defaultValue = "1")  int page,
        @RequestParam(defaultValue = "10") int size
       ) {
            Long userId = SecurityUtils.getCurrentUserId();
            // 创建分页对象，查询第1页，每页10条
            Page<ExamRecordDTO> page1 = new Page<>(page, size);
            Page<ExamRecordDTO> result = examRecordMapper.findExamRecordsByUserId(page1, userId);
            List<ExamRecordDTO> record = result.getRecords();

            Long total = result.getTotal(); // 总记录数
        Result result1=Result.success(record);
        Map<String , Long> map=new HashMap<>();
        map.put("totalCount",total);
        result1.setMap(map);
        return result1;
    }
}
